package com.bsoft.exchange.controller.invoice;

import com.bsoft.exchange.domain.ElectronicInvoiceDomain;
import com.bsoft.exchange.pojo.BillPicUrlPojo;
import com.bsoft.exchange.pojo.ElectronicInvoicePojo;
import com.bsoft.exchange.pojo.UploadingInvoicePojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.ElectronicInvoiceService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * 创建日期 : 2020/7/9
 * 创建人 : 赵太行
 * 电子发票相关接口
 */
@RestController
@RequestMapping("invoice")
public class ElectronicInvoiceController {
    @Resource
    ElectronicInvoiceService electronicInvoiceService;
    @RequestMapping(value = "/creatInvoice" ,method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity creatInvoice(@RequestBody UploadingInvoicePojo pojo){
        ResponseEntity responseEntity=new ResponseEntity();
        return responseEntity;
    }
    @RequestMapping(value = "/queryInvoiceH5URL" ,method = RequestMethod.POST,produces = "application/json")
    public ResponseEntity queryInvoiceH5URL(@RequestBody BillPicUrlPojo pojo){
        ResponseEntity responseEntity=new ResponseEntity();
        BaseResponse baseResponse= electronicInvoiceService.getH5Url(pojo);
        responseEntity.setCode(baseResponse.getCode());
        responseEntity.setMessage(baseResponse.getMessage());
        responseEntity.setData(baseResponse.getData());
        return responseEntity;
    }
    @ApiOperation(value = "查询发票列表")
    @ResponseBody
    @RequestMapping(value = "/queryInvoiceList", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity<List<ElectronicInvoiceDomain>> queryInvoiceList(@RequestBody ElectronicInvoicePojo electronicInvoicePojo) {
        ResponseEntity<List<ElectronicInvoiceDomain>> electronicInvoiceResponseEntity = new ResponseEntity();
        try {
            BaseResponse<List<ElectronicInvoiceDomain>> electronicInvoiceResponse = electronicInvoiceService.queryInvoiceList(electronicInvoicePojo);
            if (electronicInvoiceResponseEntity.getCode() == Constant.errorTag) {
                electronicInvoiceResponseEntity.setCode(Constant.errorTag);
                electronicInvoiceResponseEntity.setMessage(electronicInvoiceResponse.getMessage());
            } else {
                electronicInvoiceResponseEntity.setCode(Constant.successResponse);
                electronicInvoiceResponseEntity.setMessage(electronicInvoiceResponse.getMessage());
                electronicInvoiceResponseEntity.setData(electronicInvoiceResponse.getData());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return electronicInvoiceResponseEntity;
    }

}
